﻿using System;
using System.Collections.Generic;
using System.Linq;
using Crow.Library.RepositoryFactory;

namespace Crow.Library.Tests.Benchmarks.Application
{
    public class BusinessClass : IBenchmarkBusiness
    {
        private readonly IBenchmarkRepository _repository;

        public BusinessClass()
            : this(Repository.Get<IBenchmarkRepository>())
        {
        }

        public BusinessClass(IBenchmarkRepository repository)
        {
            _repository = repository;
        }

        #region IBenchmarkBusiness Members

        public virtual void SaveItem()
        {
            var data = new BenchmarkData
                           {
                               Name = "John",
                               Lastname = "Snow",
                               Birthdate = DateTime.Now.Subtract(TimeSpan.FromDays(459))
                           };
            _repository.InsertBenchmarkData(data);
        }

        public IList<BenchmarkData> GetItems()
        {
            return _repository.GetAllData().ToList();
        }

        public void TruncateTable()
        {
            _repository.Truncate();
        }

        #endregion
    }
}